package com.xingkeduo.business.operation.domain;

import com.xingkeduo.business.operation.service.DeptmentService;
import com.xingkeduo.business.operation.service.PictureService;
import com.xingkeduo.pojo.dto.Picture.PictureDTO;
import com.xingkeduo.pojo.query.PictureQuery;
import com.xingkeduo.pojo.table.PictureTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.DataException;
import com.xingkeduo.util.tool.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *
 * @author chenxiangda <chenxiangda@xingkeduo.com>
 * @version id:v0.1 2019年4月13日 14:37:00
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class PictureDomain {
    @Autowired
    private DeptmentService deptmentService;
    @Autowired
    private PictureService pictureService;

    public PictureTable getPictureById(Long id) throws Throwable {

        PictureTable pictureTable = pictureService.selectById(id);

        return pictureTable;
    }

    //添加
    public Long createPicture(PictureDTO pictureDTO) throws Throwable {
        PictureTable pictureTable = new PictureTable();
       pictureService.insert(pictureTable);
       return pictureTable.getId();
    }

    public List<PictureTable> getPictureList(PictureQuery pictureQuery) throws Throwable {

        List<PictureTable> pictureList = pictureService.selectLists(pictureQuery);

        return pictureList;
    }

    //分页查询
    public Page<PictureTable> getPicturePageList(PictureQuery pictureQuery) throws Throwable {
        Integer pageNo = pictureQuery.getPageNo();
        Integer pageSize = pictureQuery.getPageSize();
        Page<PictureTable> pictureTablePage = pictureService.selectPageLists(pictureQuery,pageNo,pageSize);
        return pictureTablePage;
    }

    public int modifyPicture(PictureTable pictureTable) throws Throwable {
        return pictureService.update(pictureTable);
    }
    
    //删除
    public int delPicture(Long id) throws Throwable {
        PictureTable pictureTable = new PictureTable();

        pictureTable.setId(id);
        pictureTable.setIsDelete(YesNoEnum.YES);
        int delRes = pictureService.delete(pictureTable);
        if(delRes > 0){
            return delRes;
        }else{
            throw new DataException(DataException.Type.FAIL, "删除失败");
        }
    }
}
